/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef MUSIC_SYSTEM_H
#define MUSIC_SYSTEM_H

#include <boost/shared_ptr.hpp>
#include "../model/model_class.h"
#include "../model/dom.h"
#include "../network/i_socket.h"
#include "../core/null_deleter.h"
#include "data_miner.h"
#include "file_streamer.h"

#include <string>
#include <map>
#include <exception>

using namespace std;

/** 
 * \brief This namespace includes all music-related stuff.
 * \author Michael Opitz
 */
namespace music {
	/** 
	 * \brief This class provides a facade for the whole music-system
	 */
	class music_system {
	public:
		music_system();
		~music_system() {};

		/** 
		 * \brief add_music adds new music-data to the music_system. 
		 * 
		 * \param node is the dom-node which stores all the new 
		 * music-data
		 * \param sock is the socket from the client from which the data
		 * was received.
		 */
		void add_music(boost::shared_ptr<model::dom> node, 
			boost::shared_ptr<network::i_socket> sock);
		/** 
		 * \brief remove_music removes music-data from the music_system.
		 * 
		 * \param sock is the socket, which indicates the client,
		 * whichs data should be removed.
		 */
		void remove_music(boost::shared_ptr<network::i_socket> sock);
		/** 
		 * \brief play_music loggs the title and client from which you
		 * want to play music. Moreover it returns the socket from the
		 * music-client from which you want to play music.
		 * 
		 * \param client is the name of the client.
		 * \param file is the filename of the title.
		 * 
		 * \return a shared_ptr to the socket of the client is returned.
		 */
		boost::shared_ptr<network::i_socket> play_music(
			const string &client, const string &file);
		/** 
		 * \brief suggest_title suggests a title with the apriori
		 * algorithm.
		 * 
		 * \param client is the name of the music-client whose music
		 * should be played.
		 * 
		 * \return The filename of the suggested title is returned.
		 */
		string suggest_title(const string &client);
		/** 
		 * \brief get_socket returns the socket from the apropriate
		 * music_client
		 * 
		 * \param client is the name of the music client
		 * 
		 * \return a shared_ptr to the socket of the music client is
		 * returned.
		 */
		boost::shared_ptr<network::i_socket> get_socket(
			const string &client);
		/** 
		 * \brief list_clients returns a dom-node of all available music
		 * clients with their music-data.
		 */
		boost::shared_ptr<model::dom> list_clients() const;
	private:
		boost::shared_ptr<model::model_class> _model;
		map<model::client*, boost::shared_ptr<network::i_socket> > _map;
	};
}

#endif
